package com.zpkj.eureka.consumer;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.loadbalancer.LoadBalancerClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
public class DcController {
	
	private static final Logger LOGGER = LoggerFactory.getLogger(DcController.class);
	
	@Autowired
    LoadBalancerClient loadBalancerClient;
	
	 @Autowired
	 RestTemplate restTemplate;
	 
	 @GetMapping("/consumerRibbon")
	 public String dc(){
		 return restTemplate.getForObject("http://eureka-client/dc", String.class);
	 }
	 
	 @GetMapping("/log-instance")
	 public void logInstance(){
		 ServiceInstance choose = this.loadBalancerClient.choose("eureka-client");
		 DcController.LOGGER.info("{}:{}:{}",choose.getServiceId(),choose.getHost(),choose.getPort());
	 }

}
